import React, { Component } from 'react'
import axios from 'axios'
//connect获取仓库里的值 和派发action到仓库
import {connect} from "react-redux"
export class App extends Component {
  componentDidMount(){
    axios.get("/list").then(res=>{
      const action = {
        type:"ALLlIST",
        payload:res.data.list
      }
      //通过 this.props.dispatch派发action给仓库 
      this.props.dispatch(action)
    })
  }
  render() {
    let {list} = this.props
    return (
      <div >
        app
        {
          list&&list.map((item,i)=>{
            return <p key ={i}>{item.user}</p>
          })
        }
      </div>
    )
  }
}

const mapState = (state) =>{
  console.log("state",state.reduce);
   return{
     ...state.reduce
   }
}
export default connect(mapState)(App) 
  